/*************************************************
Author: tony
Date: 10/23/2012
Description:
Notes:
*************************************************/

#ifndef __CUserShop_h__
#define __CUserShop_h__

#include "commclass.h"
#include "CTArray.h"
#include "base/CTTime.h"
#include "CShopConfig.h"

//回购的商品
class CShopBuyBackItem
{
public:
    CShopBuyBackItem()
    {
        _ucItemType = 0;
        _uiItemConfigId = 0;

        _uiItemID = 0;
        _usLevel = 0;
        _usItemCount = 0;
        _uiPrice = 0;
        _iInvalidTime = 0;
    }


    unsigned char _ucItemType;
	unsigned int  _uiItemConfigId;	//待售商品的配置ID

    unsigned int _uiItemID;         //物品ID，目前只有装备有用
    unsigned short _usLevel;        //物品等级。目前只有装备有用，表示强化等级
    unsigned short _usItemCount;    //物品数量
    int _iInvalidTime ;             //物品失效时间
	unsigned int  _uiPrice;         //回购价格. (_usItemCount个物品的总价)

    T_EQUIP_REFINE_AND_BLESS _stRefineAndBlessStats; //装备洗练和祝福(装备用)
};


#define  MYSTICAL_CLEAR_REFRESH_TIME  (23*3600) //23:00清空金币刷新次数
#define  MYSTICAL_SHOP_CANE_MAXNUM    6        //魔杖数的最大数目

//神秘商店
class CDropItemData;
class CMysticalShop
{
public:
    CMysticalShop()
    {
        Clear();
    }

    void Clear()
    {
        _ucCaneCnt = 0;
        _iRenewCaneTime = 0;
        _iClearCntTime = 0;
        _ucGoldRefreshCnt = 0;
        _astShopItem.Clear();
    }

    ~CMysticalShop()
    {
    }

    int GetCaneNum()
    {
        return _ucCaneCnt;
    }

    //返回魔杖冷却时间(单位: 秒)
    int GetCoolDownTime(int iNow)
    {
    	return _iRenewCaneTime;
    }

    int GetGoldRefreshCost ();
    void RenewCaneNum (int iCaneCDTime, int iNowTime);
    int GetShopIemList(T_SHOP_ITEM_LIST & stShopItemList);
    int GetShopItem (unsigned char ucPos, CShopItemConfig & stShopItem);
    bool HasSameItem (CDropItemData & stItem);
public:
    unsigned char _ucCaneCnt;
    unsigned char _ucGoldRefreshCnt; //金币刷新次数
    int _iRenewCaneTime;  //下次计算更新魔杖数量的时间
    int _iClearCntTime;   //下次清空金币刷新次数的时间
    CTArray<CShopItemConfig, MAX_MYSTICAL_SHOP_GRID_NUM> _astShopItem;
};

class CClanShop
{
public:
    CClanShop ()
    {
        Clear();
    }

    void Clear()
    {
        _uiClanId = 0;
        _iLastBuyTime = 0;
        _astBuyItems.Clear();
        return ;
    }

    unsigned int _uiClanId;
    int _iLastBuyTime;   //最近一次购物商品的时间
    CTArray<unsigned char, MAX_CLAN_SHOP_ITEM> _astBuyItems;  //保存已购买物品在商店中的下标
};

class CUserShop
{
public:
    CUserShop()
    {
        Clear();
    }

    virtual ~CUserShop()
    {
    }

	int Init();
    void Clear();

	int AddBuyBackItem(CShopBuyBackItem& stBuyBackItem);
    int TakeoutBuyBackItem(unsigned short usPos, CShopBuyBackItem& stBuyBackItem);
    int GetBuyBackInfo(unsigned short usPos, CShopBuyBackItem& stBuyBackItem);

    int AddClanShopItem (unsigned char ucPos);

    int GetClanShopList (T_SHOP_ITEM_LIST & stShopItemList);
public:
    unsigned int _uiGid;
	CTArray<CShopBuyBackItem, MAX_SHOP_BUY_BACK_ITEM_COUNT>  _astBuyBackItems;
    CMysticalShop _stMysticalShop;
    CClanShop _stClanShop;

    int _iClearCrystalShopTime;  //清除购买宝石商店物品时间
    CTArray<unsigned char, MAX_CRYSTAL_SHOP_COUNT> _astCrystalItems; //已在宝石商店购买的物品下标
};

#endif // __CUserShop_h__

